//
//  UINavigationController+Ext.swift
//  TTCOM-iOS
//
//  Created by Toj on 3/22/23.
//

import UIKit

public extension UINavigationController {
    
    // 导航栏 高度
    var nav_barHeight: CGFloat {
        return navigationBar.frame.height
    }
    
    // 导航栏 安全高度高度
    var nav_barFullHeight: CGFloat {
        return nav_barHeight + .sts_barHeight
    }
}

public extension UINavigationController {
    
    var nav_currentNavigationTopViewController: UIViewController? {
        return viewControllers.last
    }
    
    func nav_popToViewController(
        member mClass: UIViewController.Type,
        animated: Bool = true
    ) -> [UIViewController] {
        // 找到目标控制器
        // 目标不为nil
        guard let vc = (viewControllers.last { return $0.isMember(of: mClass) }) else {
            guard let vc = popViewController(animated: animated) else { return [] }
            return [vc]
        }
        return popToViewController(vc, animated: animated) ?? []
    }
}
